package com.x.erp.dao;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.x.erp.model.Price;
import com.x.framework.dao.BaseDao;

@Repository
public class PriceDao extends BaseDao {

	/**
	 * 根据价格查询价格信息（单位：元）
	 */
	private final static String selectCarTypeListSql = "SELECT * FROM BASE_PRICE ep WHERE ? >= ep.PRICE_FROM AND ? <= ep.PRICE_TO ";

	public Price selectPriceInfoByPrice(BigDecimal price) throws Exception {
		List<Object> params = new ArrayList<Object>();
		params.add(price);
		params.add(price);
		return this.queryForList(selectCarTypeListSql, Price.class, params).get(0);
	}

	/**
	 * 查询价格列表
	 * 
	 * @param price
	 * @return
	 * @throws Exception
	 */
	private final static String selectPriceListSql = "SELECT bp.* FROM BASE_PRICE bp WHERE 1 = 1 ";

	public List<Price> selectPriceList(Price price) throws Exception {
		return this.queryForList(selectPriceListSql, Price.class);
	}

	/**
	 * 根据具体的价格，查询所属的价格区间（单位：万元）
	 * @param price
	 * @return
	 */
	private final static String selectPriceByDetailPriceSql = "SELECT * FROM BASE_PRICE ep WHERE ? >= ep.PRICE_FROM_10000 AND ? <= ep.PRICE_TO_10000 ";

	public Price selectPriceByDetailPrice(Price price) throws Exception {
		List<Object> params = new ArrayList<>();
		params.add(price.getDetailPrice ());
		params.add(price.getDetailPrice ());
		return this.queryForList(selectPriceByDetailPriceSql, Price.class, params).get(0);
	}
}
